package com.asohofrucol.dto.util;

import com.asohofrucol.dto.RuatRegisterDTO;
import com.asohofrucol.model.ComboValue;
import com.asohofrucol.model.Ruat;

public class RuatHelperDto {

	public static RuatRegisterDTO convertToDto(Ruat ruat) {
		// implementar
		RuatRegisterDTO dto = new RuatRegisterDTO();
		dto.setEmail(ruat.getEmail());
		dto.setAddress(ruat.getAddress());
		dto.setAssociateLastName(ruat.getAssociateLastName());
		dto.setAssociateName(ruat.getAssociateName());
		dto.setAssociateVillage(ruat.getAssociateVillage());
		dto.setAssociationsMembership((ruat
				.getComboValueAssociationsMembership() != null) ? ruat
				.getComboValueAssociationsMembership().getId() : null);
		dto.setAvailabilityOfAccesRoads((ruat
				.getComboValueAvailabilityOfAccesRoads() != null) ? ruat
				.getComboValueAvailabilityOfAccesRoads().getId() : 2L);
		dto.setBornDate(ruat.getBornDate());
		dto.setCatastralIdentification(ruat.getCatastralIdentification());
		dto.setCellphone(ruat.getCellphone());
		dto.setConfidenceGrade((ruat.getComboValueConfidenceGrade() != null) ? ruat
				.getComboValueConfidenceGrade().getId() : null);
		// departamento cambia
		dto.setDepartament(ruat.getDepartament());
		dto.setDistanceMunicipalityTown(ruat.getDistanceMunicipalityTown());
		dto.setEducationalLevel((ruat.getComboValueEducationalLevel() != null) ? ruat
				.getComboValueEducationalLevel().getId() : null);
		dto.setEntitiesProvidingSupport((ruat
				.getComboValueEntitiesProvidingSupport() != null) ? ruat
				.getComboValueEntitiesProvidingSupport().getId() : 2L);
		dto.setFarm((ruat.getComboValueFarm() != null) ? ruat
				.getComboValueFarm().getId() : 1L); // por defecto si es finca
		// departameto cambia
		dto.setFarmDesc((ruat.getComboValueFarm() != null) ? ruat
				.getComboValueFarm().getDescription() : "SI");
		dto.setFarmDepartament(ruat.getFarmDepartament());
		dto.setFarmingIncome(ruat.getFarmingIncome());
		// municipio cambia
		dto.setFarmMunicipality(ruat.getFarmMunicipality());
		dto.setFarmName(ruat.getFarmName());
		dto.setFarmSector(ruat.getFarmSector());
		dto.setFarmTenure((ruat.getComboValueFarmTenure() != null) ? ruat
				.getComboValueFarmTenure().getId() : null);
		dto.setFarmTenureDesc((ruat.getComboValueFarmTenure() != null) ? ruat
				.getComboValueFarmTenure().getDescription() : null);

		dto.setFarmTotalArea(ruat.getFarmTotalArea());
		// village comostring
		dto.setFarmVillage(ruat.getFarmVillage());
		dto.setFirstLastName(ruat.getFirstLastName());
		dto.setFirstName(ruat.getFirstName());
		dto.setFollowLastName(ruat.getFollowLastName());
		dto.setFollowName(ruat.getFollowName());
		dto.setFollowProduct((ruat.getComboValueFollowProduct() != null) ? ruat
				.getComboValueFollowProduct().getId() : null);
		dto.setFrequencyOfConsultation((ruat
				.getComboValueFrequencyOfConsultation() != null) ? ruat
				.getComboValueFrequencyOfConsultation().getId() : null);
		dto.setId(ruat.getId());
		dto.setIdNumber(ruat.getIdNumber());
		dto.setIdType((ruat.getComboValueIdType() != null) ? ruat
				.getComboValueIdType().getId() : null);
		dto.setInnovationProcesses((ruat.getComboValueInnovationProcesses() != null) ? ruat
				.getComboValueInnovationProcesses().getId() : 2L);// se pone no
																	// por
																	// defecto =
																	// 2L

		dto.setInnovationProcessesDesc((dto.getInnovationProcesses() == 2L) ? "NO"
				: "SI");
		dto.setLastGrade(ruat.getLastGrade());
		dto.setMachineryAndEquipment((ruat.getComboValueMachineryAndEquipment() != null) ? ruat
				.getComboValueMachineryAndEquipment().getId() : null);
		dto.setMeansOfTransportation((ruat.getComboValueMeansOfTransportation() != null) ? ruat
				.getComboValueMeansOfTransportation().getId() : null);
		dto.setModifiedDate(ruat.getModifiedDate());
		dto.setModifierUser(ruat.getModifierUser());
		// municipio debe cambiar
		dto.setMunicipality(ruat.getMunicipality());
		dto.setNoPaved((ruat.getComboValueNoPaved() != null) ? ruat
				.getComboValueNoPaved().getId() : null);
		dto.setOriginOfCredit((ruat.getComboValueOriginOfCredit() != null) ? ruat
				.getComboValueOriginOfCredit().getId() : null);
		dto.setOriginOfCreditOther(ruat.getOriginOfCreditOther());
		dto.setPaved((ruat.getComboValuePaved() != null) ? ruat
				.getComboValuePaved().getId() : null);
		dto.setPeopleDepend(ruat.getPeopleDepend());
		dto.setReasonNotToBelong((ruat.getComboValueReasonNotToBelong() != null) ? ruat
				.getComboValueReasonNotToBelong().getId() : null);
		dto.setReasonNotToBelongDesc((ruat.getComboValueReasonNotToBelong() != null) ? ruat
				.getComboValueReasonNotToBelong().getDescription() : null);
		dto.setSecondLastName(ruat.getSecondLastName());
		dto.setSecondName(ruat.getSecondName());
		dto.setSex((ruat.getComboValueSex() != null) ? ruat.getComboValueSex()
				.getId() : null);
		dto.setStatus(ruat.getStatus());
		dto.setTelephone(ruat.getTelephone());
		dto.setTotalFamilyIncome(ruat.getTotalFamilyIncome());
		dto.setUsingCurrentCredit((ruat.getComboValueUsingCurrentCredit() != null) ? ruat
				.getComboValueUsingCurrentCredit().getId() : 2L); // por defecto
																	// no
		dto.setUsingCurrentCreditDesc((dto.getUsingCurrentCredit() == 2L) ? "NO"
				: "SI");
		// vereda como string
		dto.setVillage(ruat.getVillage());
		dto.setWasteManagementProgram((ruat
				.getComboValueWasteManagementProgram() != null) ? ruat
				.getComboValueWasteManagementProgram().getId() : 2L);// por
																		// defecto
																		// no
		dto.setWorkingInPartnership((ruat.getComboValueWorkingInPartnership() != null) ? ruat
				.getComboValueWorkingInPartnership().getId() : 2L); // por
																	// defecto
																	// no
		dto.setIdTypeDesc(ruat.getComboValueIdType().getDescription());
		dto.setSexDesc(ruat.getComboValueSex().getDescription());
		dto.setConfidenceGradeDesc(ruat.getComboValueConfidenceGrade()
				.getDescription());
		dto.setFollowProductDesc(ruat.getComboValueFollowProduct()
				.getDescription());
		dto.setFrequencyOfConsultationDesc(ruat
				.getComboValueFrequencyOfConsultation().getDescription());
		dto.setWorkingInPartnershipDesc(ruat
				.getComboValueWorkingInPartnership().getDescription());
		dto.setAssociationsMembershipDesc(ruat
				.getComboValueAssociationsMembership().getDescription());
		dto.setEntitiesProvidingSupportDesc(ruat
				.getComboValueEntitiesProvidingSupport().getDescription());
		dto.setUsingCurrentCreditDesc(ruat.getComboValueUsingCurrentCredit()
				.getDescription());
		dto.setOriginOfCreditDesc(ruat.getComboValueOriginOfCredit()
				.getDescription());
		dto.setPavedDesc(ruat.getComboValuePaved().getDescription());
		dto.setNoPavedDesc(ruat.getComboValueNoPaved().getDescription());
		dto.setMeansOfTransportationDesc(ruat
				.getComboValueMeansOfTransportation().getDescription());
		dto.setMachineryAndEquipmentDesc(ruat
				.getComboValueMachineryAndEquipment().getDescription());

		// agregados 2 = false 1 = true
		dto.setEntitiesProvidingSupportName(ruat
				.getEntitiesProvidingSupportName());
		dto.setFarmAqueduct((ruat.getComboValueFarmAqueduct() != null) ? ruat
				.getComboValueFarmAqueduct().getId() : 2L);
		if (dto.getFarmAqueduct() == 1L) {
			dto.setFarmAqueductBoolean(true);
		}
		dto.setFarmElectricPower((ruat.getComboValueFarmElectricPower() != null) ? ruat
				.getComboValueFarmElectricPower().getId() : 2L);
		if (dto.getFarmElectricPower() == 1L) {
			dto.setFarmElectricPowerBoolean(true);
		}
		dto.setFarmInternetAccess((ruat.getComboValueFarmInternetAccess() != null) ? ruat
				.getComboValueFarmInternetAccess().getId() : 2L);
		if (dto.getFarmInternetAccess() == 1L) {
			dto.setFarmInternetAccessBoolean(true);
		}
		dto.setFarmOwnWater((ruat.getComboValueFarmOwnWater() != null) ? ruat
				.getComboValueFarmOwnWater().getId() : 2L);
		if (dto.getFarmOwnWater() == 1L) {
			dto.setFarmOwnWaterBoolean(true);
		}

		dto.setWasteManagementProgramClass((ruat
				.getComboValueWasteManagementProgramClass() != null) ? ruat
				.getComboValueWasteManagementProgramClass().getId() : null);
		dto.setWasteManagementProgramClassDesc((ruat
				.getComboValueWasteManagementProgramClass() != null) ? ruat
				.getComboValueWasteManagementProgramClass().getDescription()
				: null);

		dto.setFullName(ruat.getFullName());
		dto.setFullLastName(ruat.getFullLastName());
		dto.setAltitude(ruat.getAltitude());
		dto.setWestLongitude(ruat.getWestLongitude());
		dto.setNorthLatitude(ruat.getNorthLatitude());
		return dto;
	}

	public static Ruat converToEntity(RuatRegisterDTO ruatRegisterDTO) {
		Ruat entity = new Ruat();
		// entity.setFirstName(ruatRegisterDTO.getFirstName());
		// entity.setSecondName(ruatRegisterDTO.getSecondName());
		// entity.setFirstLastName(ruatRegisterDTO.getFirstLastName());
		// entity.setSecondLastName(ruatRegisterDTO.getSecondLastName());
		// entity.setBornDate(ruatRegisterDTO.getBornDate());
		entity.setEmail(ruatRegisterDTO.getEmail());

		entity.setAddress(ruatRegisterDTO.getAddress());
		entity.setAssociateLastName(ruatRegisterDTO.getAssociateLastName());
		entity.setAssociateName(ruatRegisterDTO.getAssociateName());
		entity.setAssociateVillage(ruatRegisterDTO.getAssociateVillage());
		entity.setBornDate(ruatRegisterDTO.getBornDate());
		entity.setCatastralIdentification(ruatRegisterDTO
				.getCatastralIdentification());
		entity.setCellphone(ruatRegisterDTO.getCellphone());
		entity.setComboValueAssociationsMembership(new ComboValue(
				ruatRegisterDTO.getAssociationsMembership()));
		entity.setComboValueAvailabilityOfAccesRoads(new ComboValue(
				ruatRegisterDTO.getAvailabilityOfAccesRoads()));
		entity.setComboValueConfidenceGrade(new ComboValue(ruatRegisterDTO
				.getConfidenceGrade()));
		// departamento debe cambiar
		entity.setDepartament((ruatRegisterDTO.getDepartament()));
		entity.setComboValueEducationalLevel(new ComboValue(ruatRegisterDTO
				.getEducationalLevel()));
		entity.setComboValueEntitiesProvidingSupport(new ComboValue(
				ruatRegisterDTO.getEntitiesProvidingSupport()));
		entity.setComboValueFarm(new ComboValue(ruatRegisterDTO.getFarm()));
		// departamet debe cambiar
		entity.setFarmDepartament((ruatRegisterDTO.getFarmDepartament()));
		// municipality debe cambiar
		entity.setFarmMunicipality((ruatRegisterDTO.getFarmMunicipality()));
		entity.setComboValueFarmTenure(new ComboValue(ruatRegisterDTO
				.getFarmTenure()));
		entity.setComboValueFollowProduct(new ComboValue(ruatRegisterDTO
				.getFollowProduct()));
		entity.setComboValueFrequencyOfConsultation(new ComboValue(
				ruatRegisterDTO.getFrequencyOfConsultation()));
		entity.setComboValueIdType(new ComboValue(ruatRegisterDTO.getIdType()));
		entity.setComboValueInnovationProcesses(new ComboValue(ruatRegisterDTO
				.getInnovationProcesses()));
		entity.setComboValueMachineryAndEquipment(new ComboValue(
				ruatRegisterDTO.getMachineryAndEquipment()));

		entity.setComboValueMeansOfTransportation(new ComboValue(
				ruatRegisterDTO.getMeansOfTransportation()));
		// municipality debe cambiar
		entity.setMunicipality((ruatRegisterDTO.getMunicipality()));
		entity.setComboValueNoPaved(new ComboValue(ruatRegisterDTO.getNoPaved()));
		entity.setComboValueOriginOfCredit(new ComboValue(ruatRegisterDTO
				.getOriginOfCredit()));
		entity.setComboValuePaved(new ComboValue(ruatRegisterDTO.getPaved()));
		entity.setComboValueReasonNotToBelong(new ComboValue(ruatRegisterDTO
				.getReasonNotToBelong()));
		entity.setComboValueSex(new ComboValue(ruatRegisterDTO.getSex()));
		entity.setComboValueUsingCurrentCredit(new ComboValue(ruatRegisterDTO
				.getUsingCurrentCredit()));
		entity.setComboValueWasteManagementProgram(new ComboValue(
				ruatRegisterDTO.getWasteManagementProgram()));
		entity.setComboValueWorkingInPartnership(new ComboValue(ruatRegisterDTO
				.getWorkingInPartnership()));
		entity.setDistanceMunicipalityTown(ruatRegisterDTO
				.getDistanceMunicipalityTown());
		entity.setFarmingIncome(ruatRegisterDTO.getFarmingIncome());
		entity.setFarmName(ruatRegisterDTO.getFarmName());
		entity.setFarmSector(ruatRegisterDTO.getFarmSector());
		entity.setFarmTotalArea(ruatRegisterDTO.getFarmTotalArea());
		// villa como string
		entity.setFarmVillage(ruatRegisterDTO.getFarmVillage());
		entity.setFirstLastName(ruatRegisterDTO.getFirstLastName());
		entity.setFirstName(ruatRegisterDTO.getFirstName());
		entity.setFollowLastName(ruatRegisterDTO.getFollowLastName());
		entity.setFollowName(ruatRegisterDTO.getFollowName());
		entity.setFollowProductOther(ruatRegisterDTO.getFollowProductOther());
		entity.setId(ruatRegisterDTO.getId());
		entity.setIdNumber(ruatRegisterDTO.getIdNumber());
		entity.setLastGrade(ruatRegisterDTO.getLastGrade());
		entity.setModifiedDate(ruatRegisterDTO.getModifiedDate());
		entity.setModifierUser(ruatRegisterDTO.getModifierUser());
		entity.setOriginOfCreditOther(ruatRegisterDTO.getOriginOfCreditOther());
		entity.setPeopleDepend(ruatRegisterDTO.getPeopleDepend());
		entity.setSecondLastName(ruatRegisterDTO.getSecondLastName());
		entity.setSecondName(ruatRegisterDTO.getSecondName());
		entity.setStatus(ruatRegisterDTO.getStatus());
		entity.setTelephone(ruatRegisterDTO.getTelephone());
		entity.setTotalFamilyIncome(ruatRegisterDTO.getTotalFamilyIncome());
		// villa comostring
		entity.setVillage(ruatRegisterDTO.getVillage());

		// agregados
		entity.setEntitiesProvidingSupportName(ruatRegisterDTO
				.getEntitiesProvidingSupportName());
		// 1 = true 2 = false
		entity.setComboValueFarmAqueduct(new ComboValue((ruatRegisterDTO
				.getFarmAqueductBoolean()) ? 1L : 2L));
		entity.setComboValueFarmElectricPower(new ComboValue((ruatRegisterDTO
				.getFarmElectricPowerBoolean()) ? 1L : 2L));
		entity.setComboValueFarmInternetAccess(new ComboValue((ruatRegisterDTO
				.getFarmInternetAccessBoolean()) ? 1L : 2L));
		entity.setComboValueFarmOwnWater(new ComboValue((ruatRegisterDTO
				.getFarmOwnWaterBoolean()) ? 1L : 2L));

		entity.setComboValueWasteManagementProgramClass(new ComboValue(
				ruatRegisterDTO.getWasteManagementProgramClass()));
		
		entity.setAltitude(ruatRegisterDTO.getAltitude());
		entity.setWestLongitude(ruatRegisterDTO.getWestLongitude());
		entity.setNorthLatitude(ruatRegisterDTO.getNorthLatitude());

		return entity;
	}
}
